package gdconf

import (
	"server_cluster/common/logger"
)

// 宝箱配置表

const (
	GadgetUnlockCondAcceptParentQuest = 1 // 接取父任务 参数1:父任务id
	GadgetUnlockCondFinishParentQuest = 2 // 完成父任务 参数1:父任务id
	GadgetUnlockCondFinishFight       = 3 // 完成战斗 参数1:战斗组id
	GadgetUnlockCondGiveItem          = 4 // 上交道具 参数1:道具id 参数2:数量
	GadgetUnlockCondByOtherGadget     = 5 // 由其他交互件解锁 参数[交互件id1,交互件id2]
	GadgetUnlockCondAcceptSubQuest    = 6 // 接取父任务 参数1:父任务id
	GadgetUnlockCondFinishSubQuest    = 7 // 完成父任务 参数1:父任务id
)

type GadgetActiveConfig struct {
	GadgetActiveId int32    `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 类型非宝箱则id 为sceneID* 1000 + gadgetId
	UnlockCond     IntArray `csv:"UnlockType,omitempty"`                      // 解锁条件
	RewardId       int32    `csv:"RewardID,omitempty"`                        // 奖励id
}

func (b *GadgetActiveConfig) TableName() string {
	return "config_box"
}

func (g *GameDataConfig) saveGadgetActiveConfig() {
	saveTableToDb[GadgetActiveConfig](g.Db, readTable[GadgetActiveConfig](g.CsvPathPrefix+"Box.csv"))
}

func (g *GameDataConfig) loadGadgetActiveConfig() {
	g.GameDataMaps.GadgetActiveConfig = make(map[int32]*GadgetActiveConfig)
	for _, boxConfig := range loadTableFromDb[GadgetActiveConfig](g.Db) {
		g.GameDataMaps.GadgetActiveConfig[boxConfig.GadgetActiveId] = boxConfig
	}
	logger.Info("GadgetActiveConfig Count: %v", len(g.GameDataMaps.GadgetActiveConfig))
}

func GetGadgetActiveConfig(GadgetId int32) *GadgetActiveConfig {
	value, exist := CONF.GameDataMaps.GadgetActiveConfig[GadgetId]
	if !exist {
		logger.Info("[ConfigNotFound] GadgetActiveConfig, GadgetId: %v", GadgetId)
		return nil
	}
	return value
}

func GetGadgetActiveConfigMap() map[int32]*GadgetActiveConfig {
	return CONF.GameDataMaps.GadgetActiveConfig
}
